package cn.itcast.ratelimit;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
public class IpKeyResolver implements KeyResolver {


    /**
     * @description: 生成令牌的算法
     * @param: [exchange]
     * @return: reactor.core.publisher.Mono<java.lang.String>
     * @author dejawu
     * @date: 2021/1/3 16:42
     */
    @Override
    public Mono<String> resolve(ServerWebExchange exchange) {
        //根据IP地址生成令牌
        return Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
    }
}